package com.atguigu.cloud.hystrix.order80.controller;

import com.atguigu.cloud.common.vo.CommonResult;
import com.atguigu.cloud.hystrix.order80.service.PaymentService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/consumer/payment")
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class HystrixOrderController {
    @Resource
    private PaymentService paymentService;

    @GetMapping("/hystrix/ok/{id}")
    public CommonResult paymentInfo_OK(@PathVariable("id") Integer id) {
        return paymentService.paymentInfo_OK(id);
    }

    @GetMapping("/hystrix/timeout/{id}")
   /* @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1500")
    })*/
//    @HystrixCommand
    public CommonResult paymentInfo_TimeOut(@PathVariable("id") Integer id) {
        return paymentService.paymentInfo_TimeOut(id);
    }

    //善后方法
    public CommonResult paymentTimeOutFallbackMethod(@PathVariable("id") Integer id){
        String result ="我是消费者80,对方支付系统繁忙请10秒钟后再试或者自己运行出错请检查自己,o(╥﹏╥)o";
        return CommonResult.ok().data("result",result);
    }

    public CommonResult payment_Global_FallbackMethod(@PathVariable("id") Integer id){
        String result ="Global异常处理信息，请稍后再试，/(ㄒoㄒ)/~~";
        return CommonResult.ok().data("result",result);
    }

}
